//
//  PPFavouriteModel.m
//  
//
//  Created by GaoYongyue on 16/9/16.
//
//

#import "PPFavouriteModel.h"
#import "PPFavouritePictureModel.h"

@implementation PPFavouriteModel

@synthesize pictures;


// Insert code here to add functionality to your managed object subclass
+ (instancetype)existingFanForAlbumID:(NSNumber *)albumID
{
    PPFavouriteModel *favourite = [self find:@{@"albumID" : albumID, @"currentUserID" : DGCurrentAccount.userID}];

    if(favourite == nil) {
        favourite = [PPFavouriteModel create];
        favourite.albumID = albumID;
        favourite.currentUserID = DGCurrentAccount.userID;
        [favourite.managedObjectContext saveContext];
    }

    NSArray *pictures = [PPFavouritePictureModel where:@{@"albumID": albumID}];
    favourite.pictures = pictures;

    return favourite;
}
@end
